#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
#include <string.h>
#include <iterator>
#include <sstream>
#include <algorithm>
#include <vector>

#include "ConfigurationFile.h"
#include "Tokenizer.h"

using namespace std;

std::string FileReader::ReadInputFileLocation(std::string configFileLocation)
{
	string configLine;
	string inputFileLocation;
	ifstream infile;
	infile.open(configFileLocation.c_str());
	if(infile == NULL)
	{
		cout<<"Configuration file was not found..."<<endl;
		cout<<"Program will exit..."<<endl;
		exit(1);
	}
	while(!infile.eof()) // To get you all the lines.
	{
		getline(infile,configLine); 
		size_t inputFileStringLocation = configLine.find("@INPUT");
		if(inputFileStringLocation != string::npos)
		{
			inputFileLocation = configLine.substr(string("@INPUT=").length());
		}
	}
	infile.close();
	
	return inputFileLocation;
}

void FileReader::ReadInputFile(std::string inputFileLocation, int **inputArray, int *count)
{
	string line;
	ifstream infile;
	int lineCount = 0;
	
	infile.open(inputFileLocation.c_str());
	if(infile == NULL)
	{
		cout<<"file was not found..."<<endl;
		cout<<"Program will exit..."<<endl;
		exit(1);
	}
	while(!infile.eof() && lineCount < 1) // To get you all the lines.
	{
		getline(infile, line); 
		lineCount++;
	}

	Tokenizer::TokenizeString(line, inputArray, ",", count);
	
	if(inputArray == NULL)
	{
		cout<<"inputArray was null"<<endl;
	}
	return;
}
